package com.api.shopapi.mapper;

import com.api.shopapi.entity.CardRecord;
import com.api.shopapi.entity.dto.CardRecordDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CardRecordMapper {

    @Insert("insert into card_record (CardRecordCode,ElderlyCode,CardNumber,StaffCode,CreateTime,Content,GovernmentCode) values " +
            "(#{cardRecord.CardRecordCode},#{cardRecord.ElderlyCode},#{cardRecord.CardNumber}," +
            "#{cardRecord.StaffCode},#{cardRecord.CreateTime},#{cardRecord.Content},#{cardRecord.GovernmentCode})")
    int insert(@Param("cardRecord") CardRecord cardRecord);


    @Select("<script>" +
            "select cr.*,e.Name as ElderlyName from  card_record cr left join elderly e on e.ElderlyCode=cr.ElderlyCode " +
            "where cr.GovernmentCode=#{governmentCode}  " +
            "<if test ='cardNumber !=null and cardNumber!=\"\" '>" +
            " and cr.CardNumber =#{cardNumber} " +
            "</if>" +
            "<if test ='name !=null and  name!=\"\" '>" +
            " and e.Name = #{name} " +
            "</if> " +
            " order by  cr.CreateTime  desc " +
            "</script>")
    List<CardRecordDTO> getPage(@Param("governmentCode")String governmentCode,@Param("cardNumber")String cardNumber,
                                @Param("name")String name);





}
